<#include "common.ftl">
<?xml version="1.0" encoding="${encoding}" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageDao}<#if packageDao != "">.</#if>${nameDao}">
	
	<resultMap id="orMap" type="${nameEntity}">
		<#list properties as prop>
		<#if keyproperty?? && prop==keyproperty>
		<id property="${prop.property}" javaType="${prop.javaType}" column="${prop.column}" jdbcType="${prop.jdbcType}"/>
		<#else>
		<result property="${prop.property}" javaType="${prop.javaType}" column="${prop.column}" jdbcType="${prop.jdbcType}"/>
		</#if>
		</#list> 
	</resultMap>
    
	<sql id="fullColumn">
		<#list properties as prop>${prop.column}<#if prop_has_next>,</#if></#list>
	</sql>
	<#if insert>
    
	<insert id="insert${nameEntity}" parameterType="${nameEntity}">
		insert into ${table} 
		values (
			<#list properties as prop>#<@symbol>{</@symbol>${prop.property}<@symbol>}</@symbol><#if prop_has_next>,</#if></#list>
		)
	</insert>
	</#if>
	<#if update && keyproperty??>
	
	<update id="update${nameEntity}" parameterType="${nameEntity}">
		update ${table} set 
			<#list properties as prop><#if prop.column != keyproperty.column>${prop.column} = #<@symbol>{</@symbol>${prop.property}<@symbol>}</@symbol><#if prop_has_next>,</#if></#if></#list> 
		where ${keyproperty.column} = #<@symbol>{</@symbol>${keyproperty.property}<@symbol>}</@symbol>
	</update>
	</#if>
	<#if delete && keyproperty??>
	
	<delete id="delete${nameEntity}" parameterType="${keyproperty.javaType}">
		delete from ${table} where ${keyproperty.column} = #<@symbol>{</@symbol>${keyproperty.property}<@symbol>}</@symbol>
	</delete>
	</#if>
</mapper>